/**
 * 
 */
package com.feib.stms.dao.jdbc;


import java.sql.Types;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
import org.springframework.stereotype.Repository;

import com.feib.stms.dao.UploadFileDao;
import com.feib.stms.dao.jdbc.rowmapper.UploadFileRowMapper;
import com.feib.stms.model.Group;
import com.feib.stms.model.UploadFile;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.util.UserUtil;

/**
 * @author Jimmy Liu
 *
 */
@Repository("uploadFileDao")
public class UploadFileJdbcDao extends BaseJdbcDao implements UploadFileDao 
{
	protected OracleSequenceMaxValueIncrementer sequence;

	protected SimpleJdbcInsert uploadFileJdbcInsert;

	@Override
	protected void initDao() throws Exception {
		super.initDao();
		this.sequence = new  OracleSequenceMaxValueIncrementer(this.getDataSource(), "UPLOAD_FILE_PK_SEQ");
		this.uploadFileJdbcInsert = new  SimpleJdbcInsert(this.getDataSource());
		this.uploadFileJdbcInsert.withTableName("UPLOAD_FILE")
		.usingColumns("UPLOAD_FILE_PK", "FILE_FORMAT", "UPLOAD_USER_PK", "UPLOAD_DATE", "FILE_NAME"
				, "FILE_PATH_ON_SERVER", "DES_KEY"
				, "UPDATED_DATE", "UPDATED_BY", "CREATED_DATE", "CREATED_BY");
	}

	/* (non-Javadoc)
	 * @see com.feib.stms.dao.UploadFileDao#insert(com.feib.stms.model.UploadFile)
	 */
	public int insert(UploadFile uploadFile) {

		MapSqlParameterSource parameters = new MapSqlParameterSource();

		Long uploadFilePk = new Long(sequence.nextLongValue());
		parameters.addValue("UPLOAD_FILE_PK",  uploadFilePk, Types.NUMERIC);
		parameters.addValue("FILE_FORMAT",  uploadFile.getFileFormat(), Types.VARCHAR	);
		parameters.addValue("UPLOAD_USER_PK",  uploadFile.getUploadUser().getUserPk(), Types.NUMERIC);
		parameters.addValue("UPLOAD_DATE", uploadFile.getUploadDate(), Types.TIMESTAMP);
		parameters.addValue("FILE_NAME",  uploadFile.getFileName(), Types.VARCHAR);

		parameters.addValue("FILE_PATH_ON_SERVER",  uploadFile.getFilePathOnServer(), Types.VARCHAR);
		parameters.addValue("DES_KEY",  uploadFile.getDesKey(), Types.VARCHAR);

		parameters.addValue("UPDATED_DATE",  uploadFile.getUpdatedDate(), Types.TIMESTAMP);
		parameters.addValue("UPDATED_BY",  uploadFile.getUpdatedBy(), Types.VARCHAR);

		parameters.addValue("CREATED_DATE",  uploadFile.getCreatedDate(), Types.TIMESTAMP);
		parameters.addValue("CREATED_BY", uploadFile.getCreatedBy(), Types.VARCHAR);
		
		int updateCounts = uploadFileJdbcInsert.execute(parameters);		

		if (updateCounts > 0)
			uploadFile.setUploadFilePk(uploadFilePk);

		return updateCounts;
	}




	public SqlQueryMapProvider getSqlQueryMapProviderByUploadFile(UploadFile uploadFile, Date uploaddDateFrom, Date uploadDateTo, Date deliveryDateFrom, Date deliveryDateTo, List<String> fileFormats, PaginatedList paginatedList){


		StringBuffer sql = new StringBuffer();

		Map<String, Object> parameters = new HashMap<String, Object>();


		sql.append("SELECT UF.*");
		sql.append(",U.USER_PK ,U.USER_ID,U.USER_NAME ");
		sql.append(" , G.GROUP_NAME, G.GROUP_NO");
		sql.append(", C1.CODE_NAME AS FILE_FORMAT_NAME, C2.CODE_NAME AS FILE_STATUS_NAME "); //顯示中文名稱
		sql.append(" FROM UPLOAD_FILE UF  , APP_USER U, APP_GROUP G ,CODE_TABLE C1,CODE_TABLE C2");
		sql.append(" WHERE  UF.UPLOAD_USER_PK =U.USER_PK  AND  U.GROUP_PK=G.GROUP_PK   ");
		sql.append(" AND  UF.FILE_FORMAT = C1.CODE_VALUE AND C1.CODE_KIND = 'UPLOAD_FILE_FORMAT'");
		sql.append(" AND  UF.FILE_STATUS = C2.CODE_VALUE AND C2.CODE_KIND = 'UPLOAD_FILE_STATUS'");			

		/* 銀行端一定要輸入群組代號,其他端強制只能查詢自己群組的資料 */
		if( null!= uploadFile.getGroup() && null!=uploadFile.getGroup().getGroupPk())
		{
			sql.append(" AND UF.GROUP_PK = :UF_GROUP_PK ");
			parameters.put("UF_GROUP_PK",  uploadFile.getGroup().getGroupPk());

		}		
		if(!UserUtil.isBankGroup()){
			/*其他端 須限制可查詢的 證券母/分公司*/
			if (StringUtils.isNotEmpty(uploadFile.getUploadUser().getDealSecuritiesNos()))
			{
				List<String> dealSecuritiesNos = Arrays.asList(uploadFile.getUploadUser().getDealSecuritiesNos().split(","));// 需轉成List
				if (1 == dealSecuritiesNos.size())
				{
					sql.append(" AND UF.SECURITIES_NO = :SECURITIES_NO");
					parameters.put("SECURITIES_NO",  dealSecuritiesNos.get(0)); 
				}
				else
				{
					sql.append(" AND UF.SECURITIES_NO IN (:SECURITIES_NO)");
					parameters.put("SECURITIES_NO",  dealSecuritiesNos); 
				}

			}
		}

		//上傳經辦ID不是必要欄位
		if( null!= uploadFile.getUploadUser() && StringUtils.isNotEmpty(uploadFile.getUploadUser().getUserId()))
		{
			sql.append(" AND U.USER_ID = :UF_USER_ID ");
			parameters.put("UF_USER_ID",  uploadFile.getUploadUser().getUserId());

		}		


		if (CollectionUtils.isNotEmpty(fileFormats))
		{
			if (1 == fileFormats.size())
			{
				sql.append(" AND UF.FILE_FORMAT = :fileFormat");
				parameters.put("fileFormat",fileFormats.get(0) );
			}
			else
			{
				sql.append(" AND UF.FILE_FORMAT IN (:fileFormats)");
				parameters.put("fileFormats",fileFormats );
			}
		}	



		/* 上傳日期 */
		if (null != uploaddDateFrom && null != uploadDateTo)
		{
			// between 上傳起迄
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') >= TO_CHAR(:UPLOAD_DATE_FROM, 'YYYYMMDD')");
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') <= TO_CHAR(:UPLOAD_DATE_TO, 'YYYYMMDD')");
			parameters.put("UPLOAD_DATE_FROM",  uploaddDateFrom);
			parameters.put("UPLOAD_DATE_TO",  uploadDateTo);

		}
		else if (null != uploaddDateFrom)
		{
			// >=上傳起
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') >= TO_CHAR(:UPLOAD_DATE_FROM, 'YYYYMMDD') ");
			parameters.put("UPLOAD_DATE_FROM",  uploaddDateFrom);

		}
		else if (null != uploadDateTo)
		{
			// <= 上傳迄
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') <= TO_CHAR(:UPLOAD_DATE_TO, 'YYYYMMDD') ");
			parameters.put("UPLOAD_DATE_TO",  uploadDateTo);

		}
		else if (null != uploadFile && null != uploadFile.getUploadDate())
		{
			// 單一日期
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') = TO_CHAR(:UPLOAD_DATE_TO, 'YYYYMMDD' )");
			parameters.put("UPLOAD_DATE_TO",uploadDateTo);

		}

		/* 交割日期 deliveryDateFrom deliveryDateTo*/ 
		if (null != deliveryDateFrom && null != deliveryDateTo)
		{
			// between 交割日期起迄
			sql.append(" AND TO_CHAR(UF.DELIVERY_DATE, 'YYYYMMDD') >= TO_CHAR(:DELIVERY_DATE_FROM, 'YYYYMMDD')");
			sql.append(" AND TO_CHAR(UF.DELIVERY_DATE, 'YYYYMMDD') <= TO_CHAR(:DELIVERY_DATE_TO, 'YYYYMMDD')");
			parameters.put("DELIVERY_DATE_FROM",  deliveryDateFrom);
			parameters.put("DELIVERY_DATE_TO",  deliveryDateTo);

		}
		else if (null != deliveryDateFrom)
		{
			sql.append(" AND TO_CHAR(UF.DELIVERY_DATE, 'YYYYMMDD') >= TO_CHAR(:DELIVERY_DATE_FROM, 'YYYYMMDD') ");
			parameters.put("DELIVERY_DATE_FROM",  deliveryDateFrom);

		}
		else if (null != deliveryDateTo)
		{
			sql.append(" AND TO_CHAR(UF.DELIVERY_DATE, 'YYYYMMDD') <= TO_CHAR(:DELIVERY_DATE_TO, 'YYYYMMDD') ");
			parameters.put("DELIVERY_DATE_TO",  deliveryDateTo);

		}
		else if (null != uploadFile && null != uploadFile.getDeliveryDate())
		{
			// 單一日期
			sql.append(" AND TO_CHAR(UF.DELIVERY_DATE, 'YYYYMMDD') = TO_CHAR(:DELIVERY_DATE_TO, 'YYYYMMDD' )");
			parameters.put("DELIVERY_DATE_TO",  deliveryDateTo);

		}




		if (null != paginatedList)
		{
			if (StringUtils.isNotEmpty(paginatedList.getSortCriterion()))
			{
				sql.append(" ORDER BY ").append(paginatedList.getSortCriterion()).append(" ").append( 2==paginatedList.getSortDirection() ? "ASC" : "DESC" );
			}			
		}
		SqlQueryMapProvider sqlQueryMapProvider = new SqlQueryMapProvider(sql.toString(), parameters);
		return sqlQueryMapProvider;
	};


	public PaginatedList<UploadFile> queryForPaginatedListByUploadFile(UploadFile uploadFile, Date uploaddDateFrom, Date uploadDateTo, Date deliveryDateFrom, Date deliveryDateTo, List<String> fileFormats, PaginatedList paginatedList) {

		SqlQueryMapProvider sqlQueryMapProvider =getSqlQueryMapProviderByUploadFile(uploadFile, uploaddDateFrom, uploadDateTo, deliveryDateFrom, deliveryDateTo, fileFormats, paginatedList);
		return this.queryForPaginatedList(sqlQueryMapProvider, new UploadFileRowMapper(), paginatedList.getPageNumber(), paginatedList.getPageSize());


	}

	public UploadFile getUploadFileByPk(Long uploadFilePk) {
		StringBuffer sql = new StringBuffer();
		Map<String, Object> parameters = new HashMap<String, Object>();

		sql.append("SELECT UF.*,");
		sql.append(" U.USER_PK,U.USER_NAME ");
		sql.append(", C1.CODE_NAME AS FILE_FORMAT_NAME, C2.CODE_NAME AS FILE_STATUS_NAME"); //顯示中文名稱		
		sql.append(" FROM UPLOAD_FILE UF,APP_USER U,CODE_TABLE C1,CODE_TABLE C2 ");
		sql.append(" WHERE  UF.UPLOAD_USER_PK= U.USER_PK  AND UF.UPLOAD_FILE_PK = :UPLOAD_FILE_PK");
		parameters.put("UPLOAD_FILE_PK", uploadFilePk);
		sql.append(" AND UF.FILE_FORMAT = C1.CODE_VALUE AND C1.CODE_KIND = 'UPLOAD_FILE_FORMAT'");
		sql.append(" AND UF.FILE_STATUS = C2.CODE_VALUE AND C2.CODE_KIND = 'UPLOAD_FILE_STATUS'");

		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);


		return DataAccessUtils.singleResult(this.getSimpleJdbcTemplate().query(sql.toString(), new UploadFileRowMapper(), parameters));

	}

	public List<UploadFile> queryValidateFileByFileName(String fileName) {
		StringBuffer sql = new StringBuffer();
		Map<String, Object> parameters = new HashMap<String, Object>();

		sql.append("SELECT UF.*");
		sql.append(" FROM UPLOAD_FILE UF");
		sql.append(" WHERE UF.FILE_NAME LIKE :FILE_NAME").append(" ESCAPE '\\'");// 因檔名有 _，所以使用Like比需使用跳脫字元
		sql.append(" AND UF.FILE_STATUS != 20"); // 已刪除/審查不通過
		sql.append(" AND UF.FILE_STATUS != 50"); // 已刪除/不放行
		sql.append(" AND UF.FILE_STATUS != 70"); // 已取消

		String[] tokens = fileName.split("_");
		StringBuffer f = new StringBuffer();
		for(String t: tokens)
		{
			if (StringUtils.isNotEmpty(t))
			{
				f.append(t);
			}
			f.append("\\_");
		}

		String escapeFileName = f.toString();

		if (!fileName.endsWith("_"))
		{
			escapeFileName = f.substring(0, f.length()-2);
		}

		parameters.put("FILE_NAME",  escapeFileName + "%");

		return this.getSimpleJdbcTemplate().query(sql.toString(), new UploadFileRowMapper(), parameters);
	}

	public UploadFile copyFromTempUploadFilePk(Long tempUploadFilePk, Integer checkCount, Integer confirmCount, String preDesignatedAccount)
	{
		/* 新增主檔 */
		Long uploadFilePk = new Long(sequence.nextLongValue());
		StringBuffer sql = new StringBuffer();
		Map<String, Object> parameters = new HashMap<String, Object>();
		sql.append("INSERT INTO UPLOAD_FILE(");
		sql.append("UPLOAD_FILE_PK, GROUP_PK, FILE_FORMAT, UPLOAD_USER_PK, UPLOAD_DATE");
		sql.append(", FILE_NAME, FILE_PATH_ON_SERVER, FILE_STATUS, DELIVERY_DATE, SECURITIES_NO");
		sql.append(", BANK_BRACNCH_NO, STOCK_TYPE, DEAL_TYPE, FILE_SN, TOTAL_ITEMS");
		sql.append(", TOTAL_AMOUNT, TOTAL_NET_PAY, TOTAL_NET_INCOME, TOTAL_NET_PAY_COUNT, TOTAL_NET_INCOME_COUNT");
		sql.append(", DES_KEY, CHKSUM, FILE_MD5, PRE_DESIGNATED_ACCOUNT");
		sql.append(", CHECK_COUNT, CONFIRM_COUNT"); //所需審查人數;需達到券商流程設定門檻人數(新增時將資料複製過來), 所需放行人數;需達到券商流程設定門檻人數(新增時將資料複製過來)
		sql.append(", UPDATED_DATE, UPDATED_BY, CREATED_DATE, CREATED_BY");
		sql.append(")");
		sql.append("SELECT ");
		sql.append(":UPLOAD_FILE_PK, GROUP_PK, FILE_FORMAT, UPLOAD_USER_PK, UPLOAD_DATE");
		sql.append(", FILE_NAME, FILE_PATH_ON_SERVER, :FILE_STATUS, DELIVERY_DATE, SECURITIES_NO");
		sql.append(", BANK_BRACNCH_NO, STOCK_TYPE, DEAL_TYPE, FILE_SN, TOTAL_ITEMS");
		sql.append(", TOTAL_AMOUNT, TOTAL_NET_PAY, TOTAL_NET_INCOME, TOTAL_NET_PAY_COUNT, TOTAL_NET_INCOME_COUNT");
		sql.append(", DES_KEY, CHKSUM, FILE_MD5, :PRE_DESIGNATED_ACCOUNT");
		sql.append(", :CHECK_COUNT, :CONFIRM_COUNT");
		sql.append(", SYSDATE, CREATED_BY, SYSDATE, CREATED_BY");
		sql.append("  FROM TEMP_UPLOAD_FILE WHERE TEMP_UPLOAD_FILE_PK = :TEMP_UPLOAD_FILE_PK");

		parameters.put("UPLOAD_FILE_PK", uploadFilePk);
		parameters.put("FILE_STATUS", new Integer(0)); //已上傳
		parameters.put("CHECK_COUNT", checkCount);
		parameters.put("CONFIRM_COUNT", confirmCount);
		parameters.put("TEMP_UPLOAD_FILE_PK", tempUploadFilePk);
		parameters.put("PRE_DESIGNATED_ACCOUNT", preDesignatedAccount); // 約定帳號

		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		this.getSimpleJdbcTemplate().update(sql.toString(), parameters);

		UploadFile uploadFile = new UploadFile();
		
		uploadFile = this.getUploadFileByPk(uploadFilePk);

		/* 新增明細檔 */
		String detailTableName = null;
		String detailPk = null;
		String sequenceName = null;
		String tempDetailTableName = null;
		if (UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			detailTableName = "DELIVERY_PAYMENT";
			detailPk = "DELIVERY_PAYMENT_PK";
			sequenceName = "DELIVERY_PAYMENT_PK_SEQ";
			tempDetailTableName = "TEMP_DELIVERY_PAYMENT";
		}
		else if (UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT_CHK.equals(uploadFile.getFileFormat()))
		{
			detailTableName = "DELIVERY_PAYMENT_CHK";
			detailPk = "DELIVERY_PAYMENT_CHK_PK";
			sequenceName = "DELIVERY_PAYMENT_CHK_PK_SEQ";
			tempDetailTableName = "TEMP_DELIVERY_PAYMENT_CHK";
		}
		else if (UploadFile.UPLOAD_FILE_PURCHASE_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			detailTableName = "PURCHASE_PAYMENT";
			detailPk = "PURCHASE_PAYMENT_PK";
			sequenceName = "PURCHASE_PAYMENT_PK_SEQ";
			tempDetailTableName = "TEMP_PURCHASE_PAYMENT";
		}
		else if (UploadFile.UPLOAD_FILE_PURCHASE_RETURN_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			detailTableName = "PURCHASE_RETURN_PAYMENT";
			detailPk = "PURCHASE_RETURN_PAYMENT_PK";
			sequenceName = "PURCHASE_RETURN_PAYMENT_PK_SEQ";
			tempDetailTableName = "TEMP_PURCHASE_RETURN_PAYMENT";
		}

		sql = new StringBuffer();
		parameters = new HashMap<String, Object>();
		sql.append("INSERT INTO ").append(detailTableName).append(" (");
		sql.append(detailPk).append(", UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
		sql.append(", NET_PAY, NET_INCOME, ACCOUNT_NO_CHK, AMOUNT_CHK, DEAL_TYPE");
		sql.append(", CUSTOMER_NAME, STOCK_NO, STOCK_NAME, CHARGEBACK_PRIORITY, CHARGEBACK_PRIORITY_CODE");
		sql.append(", TELLER, DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");
		sql.append(", NET_PAY_CHKSUM, NET_INCOME_CHKSUM, ACCOUNT_NO_CHKSUM, CUSTOMER_ID_CHKSUM, CHKSUM");

		sql.append(", CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE");
		sql.append(", PRE_DESIGNATED_ACCOUNT ");
		sql.append(")");
		sql.append("SELECT ");
		sql.append(sequenceName).append(".NEXTVAL , :UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
		sql.append(", NET_PAY, NET_INCOME, ACCOUNT_NO_CHK, AMOUNT_CHK, DEAL_TYPE");
		sql.append(", CUSTOMER_NAME, STOCK_NO, STOCK_NAME, CHARGEBACK_PRIORITY, CHARGEBACK_PRIORITY_CODE");
		sql.append(", TELLER, DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");
		sql.append(", NET_PAY_CHKSUM, NET_INCOME_CHKSUM, ACCOUNT_NO_CHKSUM, CUSTOMER_ID_CHKSUM, CHKSUM");

		sql.append(", UPDATED_BY, SYSDATE, UPDATED_BY, SYSDATE");
		sql.append(", :PRE_DESIGNATED_ACCOUNT ");

		sql.append(" FROM ").append(tempDetailTableName).append(" WHERE TEMP_UPLOAD_FILE_PK = :TEMP_UPLOAD_FILE_PK");

		parameters.put("UPLOAD_FILE_PK", uploadFilePk);
		parameters.put("TEMP_UPLOAD_FILE_PK", tempUploadFilePk);
		parameters.put("PRE_DESIGNATED_ACCOUNT", preDesignatedAccount); // 約定帳號
		
		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		this.getSimpleJdbcTemplate().update(sql.toString(), parameters);

		/* 驗資檔 與 交割款檔 須再複製彙總檔 */
		if (UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT_CHK.equals(uploadFile.getFileFormat()) || UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT.equals(uploadFile.getFileFormat()))
		{
			boolean isChkFile = UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT_CHK.equals(uploadFile.getFileFormat());
			sql = new StringBuffer();
			parameters = new HashMap<String, Object>();
			sql.append("INSERT INTO ").append(isChkFile? "DELIVERY_CHK_SUM": "DELIVERY_SUM").append("( ");
			sql.append(isChkFile? "DELIVERY_CHK_SUM_PK": "DELIVERY_SUM_PK").append(", UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
			sql.append(", NET_AMOUNT, LESS_AMOUNT, DEAL_TYPE, CUSTOMER_NAME, TELLER");
			sql.append(", DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");
			sql.append(", CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE");
			sql.append(")");
			sql.append("SELECT ");
			sql.append(isChkFile ? "DELIVERY_CHK_SUM_PK_SEQ.NEXTVAL": "DELIVERY_SUM_PK_SEQ.NEXTVAL").append(" , :UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
			sql.append(", NET_AMOUNT, NULL, DEAL_TYPE, CUSTOMER_NAME, TELLER");
			sql.append(", DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");

			sql.append(", UPDATED_BY, SYSDATE, UPDATED_BY, SYSDATE");
			sql.append(" FROM ").append(isChkFile? "TEMP_DELIVERY_CHK_SUM": "TEMP_DELIVERY_SUM").append("  WHERE TEMP_UPLOAD_FILE_PK = :TEMP_UPLOAD_FILE_PK");

			parameters.put("UPLOAD_FILE_PK", uploadFilePk);
			parameters.put("TEMP_UPLOAD_FILE_PK", tempUploadFilePk);

			logger.debug("SQL: {}", sql.toString());
			logger.debug("Args: {}", parameters);
			this.getSimpleJdbcTemplate().update(sql.toString(), parameters);
		}

		return uploadFile;

	}
	
	/**
	 * 驗資轉交割
	 * @param checkCount
	 * @param confirmCount
	 * @param tempUploadFilePk
	 * @return
	 */
	public UploadFile copyFromFormat1UploadFilePk(Long fromUploadFilePk, Integer checkCount, Integer confirmCount, String preDesignatedAccount)
	{
		/* 新增主檔 */
		Long uploadFilePk = new Long(sequence.nextLongValue());
		StringBuffer sql = new StringBuffer();
		Map<String, Object> parameters = new HashMap<String, Object>();
		sql.append("INSERT INTO UPLOAD_FILE(");
		sql.append("UPLOAD_FILE_PK, GROUP_PK, FILE_FORMAT, UPLOAD_USER_PK, UPLOAD_DATE");
		sql.append(", FILE_NAME, FILE_PATH_ON_SERVER, FILE_STATUS, DELIVERY_DATE, SECURITIES_NO");
		sql.append(", BANK_BRACNCH_NO, STOCK_TYPE, DEAL_TYPE, FILE_SN, TOTAL_ITEMS");
		sql.append(", TOTAL_AMOUNT, TOTAL_NET_PAY, TOTAL_NET_INCOME, TOTAL_NET_PAY_COUNT, TOTAL_NET_INCOME_COUNT");
		sql.append(", DES_KEY, CHKSUM, FILE_MD5 ,PRE_DESIGNATED_ACCOUNT");
		sql.append(", CHECK_COUNT, CONFIRM_COUNT"); //所需審查人數;需達到券商流程設定門檻人數(新增時將資料複製過來), 所需放行人數;需達到券商流程設定門檻人數(新增時將資料複製過來)
		sql.append(", UPDATED_DATE, UPDATED_BY, CREATED_DATE, CREATED_BY");
		sql.append(")");
		sql.append("SELECT ");
		sql.append(":UPLOAD_FILE_PK, GROUP_PK, :FILE_FORMAT, UPLOAD_USER_PK, UPLOAD_DATE");
		sql.append(", FILE_NAME, FILE_PATH_ON_SERVER, :FILE_STATUS, DELIVERY_DATE, SECURITIES_NO");
		sql.append(", BANK_BRACNCH_NO, STOCK_TYPE, DEAL_TYPE, FILE_SN, TOTAL_ITEMS");
		sql.append(", TOTAL_AMOUNT, TOTAL_NET_PAY, TOTAL_NET_INCOME, TOTAL_NET_PAY_COUNT, TOTAL_NET_INCOME_COUNT");
		sql.append(", DES_KEY, CHKSUM, FILE_MD5, :PRE_DESIGNATED_ACCOUNT ");
		sql.append(", :CHECK_COUNT, :CONFIRM_COUNT");
		sql.append(", SYSDATE, CREATED_BY, SYSDATE, CREATED_BY");
		sql.append("  FROM UPLOAD_FILE WHERE UPLOAD_FILE_PK = :FORM_UPLOAD_FILE_PK");

		parameters.put("UPLOAD_FILE_PK", uploadFilePk);
		parameters.put("FILE_FORMAT", UploadFile.UPLOAD_FILE_DELIVERY_PAYMENT);
		parameters.put("FILE_STATUS", new Integer(0)); //已上傳
		parameters.put("CHECK_COUNT", checkCount);
		parameters.put("CONFIRM_COUNT", confirmCount);
		parameters.put("FORM_UPLOAD_FILE_PK", fromUploadFilePk); //來源，驗資檔pk
		parameters.put("PRE_DESIGNATED_ACCOUNT", preDesignatedAccount); //約定帳號

		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		this.getSimpleJdbcTemplate().update(sql.toString(), parameters);

		UploadFile uploadFile = new UploadFile();
		

		uploadFile = this.getUploadFileByPk(uploadFilePk);

		/* 新增明細檔 */
		String detailTableName = "DELIVERY_PAYMENT";
		String detailPk = "DELIVERY_PAYMENT_PK";
		String sequenceName = "DELIVERY_PAYMENT_PK_SEQ";
		String tempDetailTableName = "DELIVERY_PAYMENT_CHK";
		

		sql = new StringBuffer();
		parameters = new HashMap<String, Object>();
		sql.append("INSERT INTO ").append(detailTableName).append(" (");
		sql.append(detailPk).append(", UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
		sql.append(", NET_PAY, NET_INCOME, ACCOUNT_NO_CHK, AMOUNT_CHK, DEAL_TYPE");
		sql.append(", CUSTOMER_NAME, STOCK_NO, STOCK_NAME, CHARGEBACK_PRIORITY, CHARGEBACK_PRIORITY_CODE");
		sql.append(", TELLER, DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");

		sql.append(", NET_PAY_CHKSUM, NET_INCOME_CHKSUM, ACCOUNT_NO_CHKSUM, CUSTOMER_ID_CHKSUM, CHKSUM");

		sql.append(", CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE");
		sql.append(")");
		sql.append("SELECT ");
		sql.append(sequenceName).append(".NEXTVAL , :UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
		sql.append(", NET_PAY, NET_INCOME, ACCOUNT_NO_CHK, AMOUNT_CHK, DEAL_TYPE");
		sql.append(", CUSTOMER_NAME, STOCK_NO, STOCK_NAME, CHARGEBACK_PRIORITY, CHARGEBACK_PRIORITY_CODE");
		sql.append(", TELLER, DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");

		sql.append(", NET_PAY_CHKSUM, NET_INCOME_CHKSUM, ACCOUNT_NO_CHKSUM, CUSTOMER_ID_CHKSUM, CHKSUM");

		sql.append(", UPDATED_BY, SYSDATE, UPDATED_BY, SYSDATE");
		sql.append(" FROM ").append(tempDetailTableName).append(" WHERE UPLOAD_FILE_PK = :FORM_UPLOAD_FILE_PK");

		parameters.put("UPLOAD_FILE_PK", uploadFilePk);
		parameters.put("FORM_UPLOAD_FILE_PK", fromUploadFilePk);
		
		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		this.getSimpleJdbcTemplate().update(sql.toString(), parameters);
		
		/* 複製 彙總檔 */
		sql = new StringBuffer();
		parameters = new HashMap<String, Object>();
		sql.append("INSERT INTO DELIVERY_SUM ( ");
		sql.append("DELIVERY_SUM_PK, UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
		sql.append(", NET_AMOUNT, LESS_AMOUNT, DEAL_TYPE, CUSTOMER_NAME, TELLER");
		sql.append(", DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");
		sql.append(", CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE");
		sql.append(")");
		sql.append("SELECT ");
		sql.append("DELIVERY_SUM_PK_SEQ.NEXTVAL, :UPLOAD_FILE_PK, GROUP_PK, ACCOUNT_NO, DELIVERY_DATE");
		sql.append(", NET_AMOUNT, NULL, DEAL_TYPE, CUSTOMER_NAME, TELLER");
		sql.append(", DEAL_RESULT_CODE, CUSTOMER_ID, SECURITIES_NO");

		sql.append(", UPDATED_BY, SYSDATE, UPDATED_BY, SYSDATE");
		sql.append(" FROM DELIVERY_CHK_SUM WHERE UPLOAD_FILE_PK = :FORM_UPLOAD_FILE_PK");

		parameters.put("UPLOAD_FILE_PK", uploadFilePk);
		parameters.put("FORM_UPLOAD_FILE_PK", fromUploadFilePk);

		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		this.getSimpleJdbcTemplate().update(sql.toString(), parameters);

		/* 更新原始驗資檔狀態 */
		sql = new StringBuffer();
		parameters = new HashMap<String, Object>();
		sql.append("UPDATE UPLOAD_FILE SET FILE_STATUS = :FILE_STATUS");
		sql.append(" WHERE UPLOAD_FILE_PK = :FORM_UPLOAD_FILE_PK ");

		parameters.put("FILE_STATUS", new Integer(9)); //轉交割(驗資檔轉交割檔)
		parameters.put("FORM_UPLOAD_FILE_PK", fromUploadFilePk);

		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		this.getSimpleJdbcTemplate().update(sql.toString(), parameters);

		return uploadFile;

	}


	public SqlQueryMapProvider getSqlQueryMapProviderDealUploadFile(UploadFile uploadFile, Date uploaddDateFrom, Date uploadDateTo, List<String> fileFormats, List<Integer> fileStatus,PaginatedList paginatedList){


		StringBuffer sql = new StringBuffer();

		Map<String, Object> parameters = new HashMap<String, Object>();
		sql.append("SELECT UF.*");
		sql.append(", C1.CODE_NAME AS FILE_FORMAT_NAME, C2.CODE_NAME AS FILE_STATUS_NAME "); //顯示中文名稱
		sql.append(" FROM UPLOAD_FILE UF ,CODE_TABLE C1,CODE_TABLE C2");
		/*	1.交割款資料必須通過多人放行(券商自定門檻人數)，才算放行完畢。 */
		/*  2.同一份交割款資料，同一主管不能執行審查作業又執行放行作業。*/
		/*  也就是審查主管與放行主管不可為同一人；且此主管最多只能審查一次or放行一次此交割款資料。*/	
		/* 	撈取該使用者沒有UPLOAD_FILE_ACTION_LOG的檔案,就代表沒有處理過 */

		if (CollectionUtils.isNotEmpty(fileStatus))
		{   /* 放行者才有權限取消作業  抓取有該人員放行紀錄的檔案 */
			if (1 == fileStatus.size()&& fileStatus.get(0)==60)//60: 已放行/待預約(即全數放行通過)
			{
				sql.append(" WHERE 1=1 ");
				//sql.append(" WHERE NOT EXISTS (");
				//sql.append(" SELECT 'X' FROM  UPLOAD_FILE_ACTION_LOG L   ");
				//sql.append(" WHERE UF.UPLOAD_FILE_PK=L.UPLOAD_FILE_PK   ");
				//sql.append(" AND L.ACTION = :L_ACTION "  );			
				//sql.append(" AND L.USER_PK = :L_USER_PK  )");
				//parameters.put("L_ACTION",UploadFileActionLog.UPLOAD_FILE_ACTION_LOG_CONFIRM );

			}else{
				sql.append(" WHERE  NOT EXISTS (");
				sql.append(" SELECT 'X' FROM  UPLOAD_FILE_ACTION_LOG L   ");
				sql.append(" WHERE UF.UPLOAD_FILE_PK=L.UPLOAD_FILE_PK   ");
				sql.append(" AND L.USER_PK = :L_USER_PK ) ");
				parameters.put("L_USER_PK",  UserUtil.getUser().getUserPk());				
				sql.append(" AND  UF.UPLOAD_USER_PK <> :UPLOAD_USER_PK");
				
				/* 檔案上傳者不可以審查，也不可以放行。上傳審查放行這三個對檔案操作的動作，使用者對同一個檔案一次只能執行一種動作。 */
				parameters.put("UPLOAD_USER_PK",  UserUtil.getUser().getUserPk());
			
			}
		}	else{
			sql.append(" WHERE  NOT EXISTS (");
			sql.append(" SELECT 'X' FROM  UPLOAD_FILE_ACTION_LOG L   ");
			sql.append(" WHERE UF.UPLOAD_FILE_PK=L.UPLOAD_FILE_PK   ");
			sql.append(" AND L.USER_PK = :L_USER_PK  )");	
			parameters.put("L_USER_PK",  UserUtil.getUser().getUserPk());
			
			sql.append(" AND  UF.UPLOAD_USER_PK <> :UPLOAD_USER_PK");
			/* 檔案上傳者不可以審查，也不可以放行。上傳審查放行這三個對檔案操作的動作，使用者對同一個檔案一次只能執行一種動作。 */
			parameters.put("UPLOAD_USER_PK",  UserUtil.getUser().getUserPk());
		
		}
		
		sql.append(" AND  UF.FILE_FORMAT = C1.CODE_VALUE AND C1.CODE_KIND = 'UPLOAD_FILE_FORMAT'");
		sql.append(" AND  UF.FILE_STATUS = C2.CODE_VALUE AND C2.CODE_KIND = 'UPLOAD_FILE_STATUS'");			

		


		/* 所屬群組(證券公司) */
		Group group = uploadFile.getGroup();
		if (null != group && null != group.getGroupPk())
		{
			sql.append(" AND UF.GROUP_PK = :GROUP_PK");
			parameters.put("GROUP_PK", group.getGroupPk() );
		}

		/* 可查詢的 證券母/分公司*/
		if (StringUtils.isNotEmpty(uploadFile.getUploadUser().getDealSecuritiesNos()))
		{
			List<String> dealSecuritiesNos = Arrays.asList(uploadFile.getUploadUser().getDealSecuritiesNos().split(","));// 需轉成List
			if (1 == dealSecuritiesNos.size())
			{
				sql.append(" AND UF.SECURITIES_NO = :SECURITIES_NO");
				parameters.put("SECURITIES_NO",  dealSecuritiesNos.get(0)); 
			}
			else
			{
				sql.append(" AND UF.SECURITIES_NO IN (:SECURITIES_NO)");
				parameters.put("SECURITIES_NO",  dealSecuritiesNos); 
			}

		}

		if (CollectionUtils.isNotEmpty(fileFormats))
		{
			if (1 == fileFormats.size())
			{
				sql.append(" AND UF.FILE_FORMAT = :fileFormat");
				parameters.put("fileFormat",fileFormats.get(0) );
			}
			else
			{
				sql.append(" AND UF.FILE_FORMAT IN (:fileFormats)");
				parameters.put("fileFormats",fileFormats );
			}
		}	


		if (CollectionUtils.isNotEmpty(fileStatus))
		{
			if (1 == fileStatus.size())
			{
				sql.append(" AND UF.FILE_Status = :fileStatus");
				parameters.put("fileStatus",fileStatus.get(0) );
			}
			else
			{
				sql.append(" AND UF.FILE_Status IN (:fileStatus)");
				parameters.put("fileStatus",fileStatus );
			}
		}	




		/* 上傳日期 */
		if (null != uploaddDateFrom && null != uploadDateTo)
		{
			// between 上傳起迄
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') >= TO_CHAR(:UPLOAD_DATE_FROM, 'YYYYMMDD')");
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') <= TO_CHAR(:UPLOAD_DATE_TO, 'YYYYMMDD')");
			parameters.put("UPLOAD_DATE_FROM", uploaddDateFrom);
			parameters.put("UPLOAD_DATE_TO",  uploadDateTo);

		}
		else if (null != uploaddDateFrom)
		{
			// >=上傳起
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') >= TO_CHAR(:UPLOAD_DATE_FROM, 'YYYYMMDD') ");
			parameters.put("UPLOAD_DATE_FROM",  uploaddDateFrom);

		}
		else if (null != uploadDateTo)
		{
			// <= 上傳迄
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') <= TO_CHAR(:UPLOAD_DATE_TO, 'YYYYMMDD') ");
			parameters.put("UPLOAD_DATE_TO",  uploadDateTo);

		}
		else if (null != uploadFile && null != uploadFile.getUploadDate())
		{
			// 單一日期
			sql.append(" AND TO_CHAR(UF.UPLOAD_DATE, 'YYYYMMDD') = TO_CHAR(:UPLOAD_DATE_TO, 'YYYYMMDD' )");
			parameters.put("UPLOAD_DATE_TO",  uploadDateTo);

		}


		if (null != paginatedList)
		{
			if (StringUtils.isNotEmpty(paginatedList.getSortCriterion()))
			{
				sql.append(" ORDER BY ").append(paginatedList.getSortCriterion()).append(" ").append( 2==paginatedList.getSortDirection() ? "ASC" : "DESC" );
			}			
		}

		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		SqlQueryMapProvider sqlQueryMapProvider = new SqlQueryMapProvider(sql.toString(), parameters);
		return sqlQueryMapProvider;
	};

	public PaginatedList<UploadFile> queryForPaginatedListDealUploadFile(UploadFile uploadFile, Date uploaddDateFrom, Date uploadDateTo, List<String> fileFormats, List<Integer> fileStatus, PaginatedList paginatedList) {

		SqlQueryMapProvider sqlQueryMapProvider =getSqlQueryMapProviderDealUploadFile(uploadFile, uploaddDateFrom, uploadDateTo, fileFormats, fileStatus, paginatedList);
		PaginatedList<UploadFile>result = this.queryForPaginatedList(sqlQueryMapProvider, new UploadFileRowMapper(), paginatedList.getPageNumber(), paginatedList.getPageSize());
		
		/* 最後一頁，計算總計 */
		if (null != result && result.isLastPage())
		{
			sqlQueryMapProvider = getTotalSqlQueryMapProviderDealUploadFile( uploadFile, uploaddDateFrom, uploadDateTo,fileFormats,  fileStatus, paginatedList);
			
			UploadFile totalObject = this.getSimpleJdbcTemplate().queryForObject(sqlQueryMapProvider.getSql(),new UploadFileRowMapper(), sqlQueryMapProvider.getParameters());
			
			result.setTotalObject(totalObject);
		}
		
		return result;

	}
	
	public SqlQueryMapProvider getTotalSqlQueryMapProviderDealUploadFile(UploadFile uploadFile, Date uploaddDateFrom, Date uploadDateTo, List<String> fileFormats, List<Integer> fileStatus,PaginatedList paginatedList){


		StringBuffer sql = new StringBuffer();
		Map<String, Object> parameters = new HashMap<String, Object>();

		sql.append("SELECT COUNT(*) AS RECORD_COUNT, SUM(sumRpt.total_NET_PAY) AS total_NET_PAY, SUM(sumRpt.total_NET_INCOME) AS total_NET_INCOME ");		
		sql.append(", SUM(sumRpt.total_Net_Pay_COUNT) AS total_Net_Pay_COUNT");
		sql.append(", SUM(sumRpt.total_NET_INCOME_COUNT) AS total_NET_INCOME_COUNT");
		sql.append(", SUM(sumRpt.CHKSUM) AS CHKSUM ");
			
		SqlQueryMapProvider content =getSqlQueryMapProviderDealUploadFile(uploadFile, uploaddDateFrom, uploadDateTo, fileFormats, fileStatus, paginatedList);		
		
		sql.append(" from ( ");
		sql.append(content.getSql());
		sql.append(" ) sumRpt ");
		parameters.putAll(content.getParameters());

		SqlQueryMapProvider sqlQueryMapProvider = new SqlQueryMapProvider(sql.toString(), parameters);
		
		logger.debug("{}", sqlQueryMapProvider);

		
		return sqlQueryMapProvider;
	};

	

	public int updateUploadFileFileStatus(UploadFile uploadFile){
		StringBuffer sql = new StringBuffer();
		MapSqlParameterSource parameters = new MapSqlParameterSource();

		sql.append("UPDATE UPLOAD_FILE SET FILE_STATUS = :FILE_STATUS ,UPDATED_DATE = :UPDATED_DATE, UPDATED_BY= :UPDATED_BY ");

		parameters.addValue("FILE_STATUS",  uploadFile.getFileStatus(), Types.VARCHAR);
		parameters.addValue("UPDATED_DATE",  uploadFile.getUpdatedDate(), Types.TIMESTAMP);
		parameters.addValue("UPDATED_BY",  uploadFile.getUpdatedBy(), Types.VARCHAR);

		/* 審查達設定門檻人數時*/
		if (null!=uploadFile.getCheckUser()){				
			sql.append(", CHECK_USER_PK = :CHECK_USER_PK  ");
			sql.append(", CHECK_RESULT = :CHECK_RESULT  ");
			sql.append(", CHECK_DATE  = :CHECK_DATE   ");
			parameters.addValue("CHECK_USER_PK",  uploadFile.getCheckUser().getUserPk(), Types.NUMERIC);
			parameters.addValue("CHECK_RESULT",  convertToInteger(uploadFile.getCheckResult()), Types.VARCHAR);
			parameters.addValue("CHECK_DATE",  uploadFile.getUpdatedDate(), Types.TIMESTAMP);				
		}
		/* 放行達設定門檻人數時 */
		if (null!=uploadFile.getConfirmUser()){				
			sql.append(", CONFIRM_USER_PK  = :CONFIRM_USER_PK   ");
			sql.append(", CONFIRM_RESULT  = :CONFIRM_RESULT   ");
			sql.append(", CONFIRM_DATE   = :CONFIRM_DATE    ");
			parameters.addValue("CONFIRM_USER_PK", uploadFile.getConfirmUser().getUserPk(), Types.NUMERIC);
			parameters.addValue("CONFIRM_RESULT", convertToInteger(uploadFile.getConfirmResult()), Types.VARCHAR);
			parameters.addValue("CONFIRM_DATE",  uploadFile.getUpdatedDate(), Types.TIMESTAMP);					
		}

		/* 資料取消時 */
		if (null!=uploadFile.getCancelUser()){				
			sql.append(", CANCEL_USER_PK  = :CANCEL_USER_PK   ");
			sql.append(", CANCEL_DATE   = :CANCEL_DATE    ");
			parameters.addValue("CANCEL_USER_PK",  uploadFile.getCancelUser().getUserPk(), Types.NUMERIC);
			parameters.addValue("CANCEL_DATE",  uploadFile.getUpdatedDate(), Types.TIMESTAMP);					
		}

		sql.append(" WHERE UPLOAD_FILE_PK = :UPLOAD_FILE_PK");
		parameters.addValue("UPLOAD_FILE_PK",  uploadFile.getUploadFilePk(), Types.NUMERIC);


		logger.debug("SQL: {}", sql.toString());
		logger.debug("Args: {}", parameters);
		return this.getSimpleJdbcTemplate().update(sql.toString(), parameters);
	}

	public int getUploadFileCheckCount(Long uploadFilePk) {

		/* 查詢 SQL */
		StringBuffer sql = new StringBuffer();
		/* 查詢條件 */
		MapSqlParameterSource parameters = new MapSqlParameterSource();
		sql.append("SELECT  CHECK_COUNT  FROM UPLOAD_FILE  " );
		sql.append("WHERE UPLOAD_FILE_PK = :UPLOAD_FILE_PK  ");
		parameters.addValue("UPLOAD_FILE_PK",  uploadFilePk, Types.NUMERIC);

		UploadFile uploadFile=DataAccessUtils.singleResult(this.getSimpleJdbcTemplate().query(sql.toString(), new UploadFileRowMapper(), parameters));
		int uploadFileCheckCount=0;
		if(null!=uploadFile && null!=uploadFile.getCheckCount())
			uploadFileCheckCount = uploadFile.getCheckCount();
		return uploadFileCheckCount;

	}

	public int getUploadFileConfirmCount(Long uploadFilePk) {
		/* 查詢 SQL */
		StringBuffer sql = new StringBuffer();
		/* 查詢條件 */
		MapSqlParameterSource parameters = new MapSqlParameterSource();
		sql.append("SELECT  CONFIRM_COUNT  FROM UPLOAD_FILE  " );
		sql.append("WHERE UPLOAD_FILE_PK = :UPLOAD_FILE_PK  ");
		parameters.addValue("UPLOAD_FILE_PK",  uploadFilePk, Types.NUMERIC);

		UploadFile uploadFile=DataAccessUtils.singleResult(this.getSimpleJdbcTemplate().query(sql.toString(), new UploadFileRowMapper(), parameters));
		int uploadFileConfirmCount=0;
		if(null!=uploadFile && null!=uploadFile.getConfirmCount())
			uploadFileConfirmCount = uploadFile.getConfirmCount();
		return uploadFileConfirmCount;

	};





}

